package cn.tedu.ivos2.application.controller;

import cn.tedu.ivos2.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos2.application.pojo.dto.ApplicationSaveDTO;
import cn.tedu.ivos2.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos2.application.service.ApplicationService;
import cn.tedu.ivos2.base.response.JsonResult;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/application/")
@Slf4j
public class AppliactionController {
    @Autowired
    private ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult saveApplication(ApplicationSaveDTO applicationSaveDTO){
        log.debug("申请_申请/修改的数据:{}",applicationSaveDTO);
        applicationService.save(applicationSaveDTO);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
        log.debug("申请_查询数据条件:{}",applicationQuery);
        List<ApplicationVO>applicationList=applicationService.select(applicationQuery);
        log.debug("申请_查询结果:{}",applicationList);
        return JsonResult.ok(applicationList);
    }
    @PostMapping("cancel/{id}")
    public JsonResult cencelApp(@PathVariable Long id){
        log.debug("撤销申请id:{}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }

    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId,@PathVariable Long vehicleId){
         log.debug("分配车辆_分配车辆的id{},申请单的id{}",vehicleId,applicationId);
         applicationService.distribute(applicationId,vehicleId);
         return JsonResult.ok();
    }

    @PostMapping("back/{applicationId}/{vehicleId}")
    public JsonResult back(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("还车_申请单:{},车辆id:{}",applicationId,vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
